﻿using System.Collections.Generic;
using System.Data;
using MaLu.Data;
using System;

namespace MaLu.BusiLogic
{
    public class BLAttach
    {
        public static void SaveAttach(IDbProvider provider, Guid pid, string filename, string filepath, string fielsavepath, long size)
        {
            List<IDataParameter> paraList = new List<IDataParameter>();
            paraList.Add(SqlHelper.Instance.CreateParameter("@AID", DataType.GUID, pid));
            paraList.Add(SqlHelper.Instance.CreateParameter("@FileName", DataType.VarChar, 255, filename));
            paraList.Add(SqlHelper.Instance.CreateParameter("@FilePath", DataType.VarChar, 255, filepath));
            paraList.Add(SqlHelper.Instance.CreateParameter("@FileSavePath", DataType.VarChar, 1000, fielsavepath));
            paraList.Add(SqlHelper.Instance.CreateParameter("@Size", DataType.Double, size));

            SqlHelper.Instance.ExecuteProcedure(provider, "Proc_SaveAttach", paraList.ToArray());
        }


        public static DataTable GetAttachList(IDbProvider provider, string ids)
        {
            string where = string.Empty;
            if (ids != string.Empty)
            {
                where = "'" + ids.Trim(new char[] { ',' }).Replace(",", "','") + "'";
            }
            else
            {
                where = "'" + Guid.Empty.ToString() + "'";

            }


            return SqlHelper.Instance.ExecuteDataTable(provider, " SELECT PhysicalFilePath, Attachments.AttachmentID,Attachments.DisplayFileName from Attachments where AttachmentID in(" + where + ")");
        }
    }
}
